﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace team33_ass3
{
    public class GameObject
    {
        public Model model { get; set; }
        public Vector3 position { get; set; }
        public Matrix world { get; set; }
        protected float scaleValue;

        Matrix[] boneTransforms;

        public GameObject()
        {
            model = null;
            position = Vector3.Zero;
        }

        public GameObject(Model model, Vector3 position)
        {
            this.model = model;
            this.position = position;
            boneTransforms = new Matrix[model.Bones.Count];
            scaleValue = 1f;
        }

        public void Draw(Matrix world, Matrix view, Matrix projection)
        {
            // Look up combined bone matrices for the entire model.
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            // Draw the model
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = boneTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(scaleValue) * world;
                    effect.View = view;
                    effect.Projection = projection;

                    effect.EnableDefaultLighting();
                }

                mesh.Draw();
            }
        }
    }
}
